﻿using System;
using PhiStore.Policies;
using PhiStore.Threading;

namespace PhiStore.Tests
{
    class NegotiationThread : Boostable
    {
        public Channel<string> ToThread;
        public Channel<bool> FromThread;

        private PhiClient<double> client;
        private Policy policy;
        public NegotiationThread(PhiClient<double> client, Policy pol)
        {
            ToThread = new Channel<string>(10);
            FromThread = new Channel<bool>(1);
            this.client = client;
            this.policy = pol;
        }

        public void Run()
        {
            try
            {
                while (true)
                {
                    string keyToCreate = ToThread.Receive();

                    double valueToWrite = double.Parse(keyToCreate.Replace("otherkeyclient", ""));

                    bool result = MethodTest<double>.Create(keyToCreate, valueToWrite, policy, client, true);

                    FromThread.Send(result);

                }

            }
            catch (Exception)
            {
                //bye bye
            }
        }
    }
}
